import 'package:honeypotflutter/modules/cabinet/model/cabinet_form_earnings_model.dart';
import 'package:honeypotflutter/net/public_http.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_modal.dart';
import '../model/cabinet_form_deliver_info_model.dart';
import '../model/cabinet_form_deliver_model.dart';
import '../model/cabinet_form_earnings_info_model.dart';

class CabinetFormApi {
  /*
  * 收益列表
  * */
  static Future<List<CabinetFormEarningsModel>> earningsList({String? startTime, String? endTime, int page = 1}) async {
    try {
      Map<String, dynamic> param = {
        "Page": page,
        "StartTime": startTime,
        "EndTime": endTime,
        "PageSize": 50,
      };
      List result = await MGHttp.get(
        "api/services/app/FinanceReport/GetMyReportsOverview",
        params: param,
      );
      List<CabinetFormEarningsModel> listModel = result.map((e) => CabinetFormEarningsModel.fromJson(e)).toList();
      return listModel;
    } catch (error) {
      MGModal.totalError(error);
      return Future.error(error);
    }
  }

  /*
  * 收益详情
  * */
  static Future<List<CabinetFormEarningsInfoModel>> earningsInfo({String? date, int page = 1}) async {
    try {
      Map<String, dynamic> param = {
        "Page": page,
        "StartTime": date,
        "EndTime": date,
        "PageSize": 50,
      };
      List result = await MGHttp.get(
        "api/services/app/FinanceReport/GetMyReports",
        params: param,
      );
      List<CabinetFormEarningsInfoModel> listModel = result.map((e) => CabinetFormEarningsInfoModel.fromJson(e)).toList();
      return listModel;
    } catch (error) {
      MGModal.totalError(error);
      return Future.error(error);
    }
  }

  /*
  * 投递列表
  * */
  static Future<List<CabinetDeliverListModel>> deliverList({String? startTime, String? endTime, int page = 1}) async {
    try {
      Map<String, dynamic> param = {
        "Page": page,
        "StartTime": startTime,
        "EndTime": endTime,
        "PageSize": 50,
      };
      List result = await MGHttp.get(
        "api/services/app/DeliveryReport/GetMyReportsOverview",
        params: param,
      );
      List<CabinetDeliverListModel> listModel = result.map((e) => CabinetDeliverListModel.fromJson(e)).toList();
      return listModel;
    } catch (error) {
      MGModal.totalError(error);
      return Future.error(error);
    }
  }

  /*
  * 收益详情
  * */
  static Future<List<CabinetDeliverListInfoModel>> deliverInfo({String? date, int page = 1}) async {
    try {
      Map<String, dynamic> param = {
        "Page": page,
        "StartTime": date,
        "EndTime": date,
        "PageSize": 50,
      };
      List result = await MGHttp.get(
        "api/services/app/DeliveryReport/GetMyDeliveryReports",
        params: param,
      );
      List<CabinetDeliverListInfoModel> listModel = result.map((e) => CabinetDeliverListInfoModel.fromJson(e)).toList();
      return listModel;
    } catch (error) {
      MGModal.totalError(error);
      return Future.error(error);
    }
  }
}
